//
//  ThreeImageCell.m
//  futureLive
//
//  Created by zhoubiwen on 15/11/17.
//  Copyright © 2015年 ZHOU_LI_SUN. All rights reserved.
//

#import "ThreeImageCell.h"
#import "HomeModel.h"
#import "URLs.h"
#import <UIImageView+WebCache.h>
@interface ThreeImageCell ()
@property (strong, nonatomic) IBOutlet UIImageView *firstImageView;
@property (strong, nonatomic) IBOutlet UIImageView *secondImageView;
@property (strong, nonatomic) IBOutlet UIImageView *thirdImageView;

@end

@implementation ThreeImageCell


- (void)setHomeModel:(HomeModel *)homeModel {
    
    if (_homeModel != homeModel) {
        _homeModel = nil;
        _homeModel = homeModel;
        [self layoutModel];
    }
}

- (void)layoutModel {
    
//    HomeImageModel *model = self.homeModel.list.firstObject;
//    [self.oneImageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
    NSArray *array = @[self.secondImageView,self.thirdImageView,self.firstImageView];
    for (int i = 0; i < self.homeModel.list.count; i++) {
        HomeImageModel *model = self.homeModel.list[i];
        UIImageView *imageView = array[i];
        [imageView sd_setImageWithURL:[NSURL URLWithString:model.img]];
    }

}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.contentView];
    CGFloat width = screen_width - screen_width  / 2.8;
    
    NSUInteger index = 0;
    if (touchPoint.x >= width) {
        index = 2;
    }else {
        if (touchPoint.y >= screen_width / 4) {
            index = 1;
        }else index = 0;
    }
    if ([self.delegate respondsToSelector:@selector(didClickThreeImageCellWithIndex:homeModel:)]) {
        [self.delegate didClickThreeImageCellWithIndex:index homeModel:self.homeModel];
    }
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
